package com.andy.qi.domain.room;

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.andy.qi.service.GameMgr;
import com.andy.qi.service.RoomConf;

@Entity
@Table(name = "t_rooms")
public class Room {

    @Id
    public String uuid;
    @Column(unique = true)
    public String id;
    public int createTime;
    public String ip;
    public int port;
    @Column(name = "base_info")
    @Convert(converter = RoomConfConverter.class)
    public RoomConf conf;
    public int nextButton;
    public int numOfGames;
    
    @Column(length = 1000)
    @Convert(converter = SeatsConverter.class)
    public Seat[] seats;
    
    @Transient
    public GameMgr gameMgr;
    @Transient
    public RoomDr dr;
    
    
    public Room() {
    }



    public String getUuid() {
        return uuid;
    }



    public void setUuid(String uuid) {
        this.uuid = uuid;
    }



    public String getId() {
        return id;
    }



    public void setId(String id) {
        this.id = id;
    }


    public String getIp() {
        return ip;
    }



    public void setIp(String ip) {
        this.ip = ip;
    }



    public int getPort() {
        return port;
    }



    public void setPort(int port) {
        this.port = port;
    }
    
    
    public static String genUuid() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String genId() {
        String roomId = "";
        for(int i = 0; i < 6; ++i) {
            roomId += (int)Math.floor(Math.random() * 10);
        }
        return roomId;
    }

    

}
